package com.ruijie.autotest.log.common.crypto;

import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

public class DESAlgorithm implements Algorithm {
	@Override
	public SecretKey createSecretKey(String password) {
		try {
			return SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(password.getBytes()));
		} catch (InvalidKeySpecException | NoSuchAlgorithmException | InvalidKeyException e) {
			throw new RuntimeException("failed to create SecretKey.", e);
		}
	}

	@Override
	public String algorithm() {
		return "DES";
	}
}
